import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from GoogleFreeTrans import Translator


class MyWindow(QWidget):
    def __init__(self):
        super(MyWindow, self).__init__()
        self.setWindowTitle('jaTrans')

        self.translator1 = Translator.translator(src='en', dest='ja')
        self.translator2 = Translator.translator(src='en', dest='ja')

        trans_btn_en = QPushButton('en->ja')
        trans_btn_cn = QPushButton('cn->ja')

        btns = QVBoxLayout()
        btns.addWidget(trans_btn_en)
        btns.addWidget(trans_btn_cn)
        btns_widgt = QWidget()
        btns_widgt.setLayout(btns)
        # buttons in transform

        self.will_be_trans = QTextEdit()
        self.target_mess_to_read = QTextEdit()

        will_be_trans_and_trans_btns = QHBoxLayout()
        will_be_trans_and_trans_btns.addWidget(self.will_be_trans)
        will_be_trans_and_trans_btns.addWidget(btns_widgt)
        will_be_trans_and_trans_btns_widgt = QWidget()
        will_be_trans_and_trans_btns_widgt.setLayout(will_be_trans_and_trans_btns)
        main_message_panel = QVBoxLayout()
        main_message_panel.addWidget(will_be_trans_and_trans_btns_widgt)
        main_message_panel.addWidget(self.target_mess_to_read)

        self.setLayout(main_message_panel)
        trans_btn_en.clicked.connect(self.trans_en)
        trans_btn_cn.clicked.connect(self.trans_cn)

    def trans_en(self):
        # print(1)
        english_mess = self.will_be_trans.toPlainText()
        japan_mess = self.translator1.translate(english_mess)
        self.target_mess_to_read.setHtml("<font color='red'>" + japan_mess + "</font>")

    def trans_cn(self):
        # print(2)
        Chinese_mess = self.will_be_trans.toPlainText()
        japan_mess = self.translator1.translate(Chinese_mess)
        self.target_mess_to_read.setHtml("<font color='red'>" + japan_mess + "</font>")


if __name__ == '__main__':
    app = QApplication(sys.argv)
    myshow = MyWindow()
    myshow.show()
    sys.exit(app.exec_())
